package com.monkeygroup.mygoplus.view.home.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.monkeygroup.mygoplus.R;
import com.monkeygroup.mygoplus.base.BaseActivity;
import com.monkeygroup.mygoplus.commit.thing.vo.RentCommitVO;
import com.monkeygroup.mygoplus.common.utils.StringUtil;
import com.monkeygroup.mygoplus.common.utils.image.Images;
import com.monkeygroup.mygoplus.http.RequestUrl;
import com.monkeygroup.mygoplus.http.ThingsHttpModel;
import com.monkeygroup.mygoplus.thing.vo.MyImageVO;
import com.monkeygroup.mygoplus.thing.vo.RentVO;
import com.monkeygroup.mygoplus.thing.vo.UserVO;
import com.monkeygroup.mygoplus.thing.vo.ZoneVO;
import com.monkeygroup.mygoplus.view.home.adapter.SellHousePageAdapter;



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 買房
 * Created by admin on 2017/4/24.
 */

public class SellHouseActivity extends BaseActivity implements View.OnClickListener {

    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;

    public static void gotoActivity(Activity activity) {
        Intent intent = new Intent(activity,
                SellHouseActivity.class);

        activity.startActivity(intent);
    }

    private LayoutInflater inflater;

    private ImageView imgBack;
    private TextView txtTitle;
    private TextView txtTop;

    private TextView txtZone,txtWay,txtPrice,txtSell;
    private ImageView imgZone,imgWay,imgPrice,imgSell;

    private LinearLayout llSearch;
    private RelativeLayout layoutTitle;

    private LinearLayout zoneRed,priceRed,sellRed,wayRed;

    private TextView txtSearchContent,etSearchContent;

    private LinearLayout llChoose,llWay;
    private List<String> leftListItems;
    private List<ZoneVO> centerListItems;
    private List<ZoneVO> rigthListItems;
    private List<String> wayList,wayRightList,priceList,sellList,sellRightList;


    private PopupWindow waypop,pop,pricepop,sellpop,searchpop,sortpop,pricesendpop;
    private  List<String> strList,sortList;

    private PullToRefreshListView houseList;
    private SellHousePageAdapter  sellHousePageAdapter;

    private PriceAdapter priceAdapter;

    private CenterAdapter center;
    private RightAdapter right;
    private LeftAdapter left;

    private SellLeftAdapter lAdapter;

    private WayAdapter adapter;
    private ListView rightWay;
    private WayRightAdapter wayRightAdapter;

    private LinearLayout llData,defaultPage;

    //自订
    private SellRightAdapter rAdapter;

    private ListView rightListView;
    //弹出框数据
    List<ZoneVO> provinceVOs,cityVOs,areaVOs,stationVOs,linesVOs;
    //参数
    private Map<String,String> params;
    private RentCommitVO requestVO;
    //請求
    private ThingsHttpModel httpThingsModel,httpThingsDetailModel;

    List<RentVO> thingsModel;


    private TextView maxPrice,minPrice;

    @Override
    public void setContentView() {
        setContentView(R.layout.activity_sell_house);
    }

    @Override
    public void initView() {

        inflater = LayoutInflater.from(SellHouseActivity.this);

        imgBack = (ImageView) findViewById(R.id.img_back);
        txtTitle = (TextView) findViewById(R.id.txt_title);
        txtTop = (TextView) findViewById(R.id.txt_top);

        llData =  (LinearLayout) findViewById(R.id.ll_data);
        defaultPage =  (LinearLayout) findViewById(R.id.default_page);


        txtZone = (TextView) findViewById(R.id.txt_zone);
        txtWay= (TextView) findViewById(R.id.txt_way);
        txtPrice = (TextView) findViewById(R.id.txt_price);
        txtSell = (TextView) findViewById(R.id.txt_sell);

        imgZone = (ImageView) findViewById(R.id.img_zone);
        imgWay= (ImageView) findViewById(R.id.img_way);
        imgPrice= (ImageView) findViewById(R.id.img_price);
        imgSell= (ImageView) findViewById(R.id.img_sell);

        llSearch = (LinearLayout) findViewById(R.id.ll_search);

        zoneRed = (LinearLayout)findViewById(R.id.img_zone_red);
        wayRed = (LinearLayout)findViewById(R.id.img_way_red);
        priceRed = (LinearLayout)findViewById(R.id.img_price_red);
        sellRed = (LinearLayout)findViewById(R.id.img_sell_red);

        txtSearchContent = (TextView)findViewById(R.id.txt_search_content);
        etSearchContent = (TextView)findViewById(R.id.et_search_content);


        txtTitle.setText("買房");

        llChoose = (LinearLayout) findViewById(R.id.ll_choose);
        llWay = (LinearLayout) findViewById(R.id.ll_way);
        layoutTitle = (RelativeLayout) findViewById(R.id.layout_title);

        houseList = (PullToRefreshListView) findViewById(R.id.lv_result);
        sellHousePageAdapter = new SellHousePageAdapter(getApplication(),R.layout.activity_sell_house_item);
        houseList.setAdapter(sellHousePageAdapter);
//        houseList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//
//            }
//        });

        wayList = new ArrayList<String>();
        wayRightList= new ArrayList<String>();
        centerListItems = new ArrayList<ZoneVO>();
        rigthListItems = new ArrayList<ZoneVO>();
        //     rigthListItems.add(vo);
        leftListItems = new ArrayList<String>();
        strList = new ArrayList<String>();
        priceList = new ArrayList<String>();
        sellList = new ArrayList<String>();
        sellRightList= new ArrayList<String>();
        sortList= new ArrayList<String>();

        requestVO = new RentCommitVO();
        params = requestVO.toMap();


        initZonePopwindow();
        initWayPopwindow();
        initPricePopWindow();
        initPriceSendPopWindow();
        initSellPopwindow();
        initSearchPopwindow();
        initSortPopwindow();

     //   Intent intent = getIntent();//获取用于激活它的意图对象

     //   Bundle bundle = intent.getExtras();
     //   String type = bundle.getString("type");

        initZoneData();
        fillZone(0);

        initRequest();
    }

    @Override
    protected void onResume() {
        super.onResume();
        sellHousePageAdapter.enableItemChoser();
    }

    private void initZoneData(){


        InputStream inputStream = getResources().openRawResource(R.raw.state);
        provinceVOs = getString("",inputStream);

        InputStream cityinputStream = getResources().openRawResource(R.raw.city);
        cityVOs = getString("15801",cityinputStream);

        InputStream areainputStream = getResources().openRawResource(R.raw.area);
        areaVOs = getString("",areainputStream);

        //读地铁数据
        InputStream lineInputStream = getResources().openRawResource(R.raw.line);
        linesVOs = getString("1580110",lineInputStream);

    }
    private void initRequest(){

//        ThingsHttpModel httpTimeModel = new ThingsHttpModel("http://www.mygo.com/mygoappapi/gettimestamp", new ThingsHttpModel.SimpleOnHttpRequestListener() {
//            @Override
//            public void onRequestFinished(String resultCode, Integer timestamp) {
//                if(resultCode.equals("ERROR_OK")){
//                    String MD5 = EncodeUtil.getMd5("http://www.mygo.com/mygoappapi/getproperty . “~@~@~@” . "+timestamp+" . “~@~@~@” . 20120712");
//                    Log.e("测试：",MD5);
                          httpThingsModel = new ThingsHttpModel(RequestUrl.thingsbuyUrl, params ,
                            new ThingsHttpModel.SimpleOnHttpRequestListener() {
                                @Override
                                public void onRequestFinished(String resultCode, Integer timestamp) {


                                }
                                @Override
                                public void onRequestFinished(String resultCode, Object property, Object user, Object users, Object circuit, Object img) {
                                    Gson gson = new Gson();
                                    thingsModel = gson.fromJson(gson.toJson(property), new TypeToken<List<RentVO>>() {}.getType());
                                   if(requestVO.isFirstPage()){
                                       sellHousePageAdapter.clear();
                                   }
                                    if(requestVO.isFirstPage()&&(thingsModel==null || thingsModel.size()==0)){
                                        llData.setVisibility(View.GONE);
                                        defaultPage.setVisibility(View.VISIBLE);
                                    }
                                    else{
                                        llData.setVisibility(View.VISIBLE);
                                        defaultPage.setVisibility(View.GONE);
                                        for (RentVO rentVO:thingsModel){
                                            sellHousePageAdapter.add(rentVO);
                                        }


                                    }
                                    sellHousePageAdapter.notifyDataSetChanged();
                                    houseList.onRefreshComplete();
                                }

                                @Override
                                public void onBuildingRequestFinished(String resultCode, Object building, Object user, Object users, Object circuit, Object img) {

                                }

                                @Override
                                public void onCommunityRequestFinished(String resultCode, Object community, Object user, Object users, Object circuit, Object img) {

                                }
                            },true);
                    httpThingsModel.requestThings();
//                }
//            }
//            @Override
//            public void onRequestFinished(String resultCode, Object property, Object[] user, Object[] users, Object[] circuit, Object[] img) {}
//        },true);
//        httpTimeModel.requestMyGoTime();
    }

    public void initDetailRequest(String param) {
        httpThingsDetailModel = new ThingsHttpModel(RequestUrl.getPropertyUrl + param,
                new ThingsHttpModel.SimpleOnHttpRequestListener() {
                    @Override
                    public void onRequestFinished(String resultCode, Integer timestamp) {

                    }

                    @Override
                    public void onRequestFinished(String resultCode, Object property, Object user, Object users, Object circuit, Object img) {
                        Gson gson = new Gson();
                        List<MyImageVO> imgModel = gson.fromJson(gson.toJson(img), new TypeToken<List<MyImageVO>>() {
                        }.getType());
                        RentVO propertyModel = gson.fromJson(gson.toJson(property), new TypeToken<RentVO>() {
                        }.getType());
                        UserVO userVO = gson.fromJson(gson.toJson(user), new TypeToken<UserVO>() {
                        }.getType());

                        Bundle bundle = new Bundle();
                        bundle.putSerializable("imgModel", (Serializable) imgModel);
                        bundle.putSerializable("propertyModel", propertyModel);
                        bundle.putSerializable("userVO", userVO);
                        Intent intent = new Intent(SellHouseActivity.this,ThingsDetailActivity.class);
                        intent.putExtra("param", bundle);
                        SellHouseActivity.this.startActivityForResult(intent, 3);
                    }

                    @Override
                    public void onBuildingRequestFinished(String resultCode, Object building, Object user, Object users, Object circuit, Object img) {

                    }

                    @Override
                    public void onCommunityRequestFinished(String resultCode, Object community, Object user, Object users, Object circuit, Object img) {

                    }
                }, true);
    }

    @Override
    public void setListener() {
        findViewById(R.id.img_back).setOnClickListener(this);
        findViewById(R.id.txt_title).setOnClickListener(this);
        findViewById(R.id.txt_top).setOnClickListener(this);

        findViewById(R.id.ll_zone).setOnClickListener(this);
        findViewById(R.id.ll_way).setOnClickListener(this);
        findViewById(R.id.ll_price).setOnClickListener(this);
        findViewById(R.id.ll_sell).setOnClickListener(this);

        findViewById(R.id.ll_search).setOnClickListener(this);
        findViewById(R.id.floating_button).setOnClickListener(this);


    }

    @Override
    public void doEvent() {

        imgBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        txtTop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                ((TextView)findViewById(R.id.txt_zone)).setText("區域");
                ((TextView)findViewById(R.id.txt_way)).setText("用途");
                ((TextView)findViewById(R.id.txt_price)).setText("價格");
                ((TextView)findViewById(R.id.txt_sell)).setText("自訂");

                ((ImageView)findViewById(R.id.img_zone)).setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));
                ((ImageView)findViewById(R.id.img_way)).setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));
                ((ImageView)findViewById(R.id.img_price)).setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));
                ((ImageView)findViewById(R.id.img_sell)).setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));

                etSearchContent.setVisibility(View.GONE);
                txtSearchContent.setVisibility(View.VISIBLE);


                left.setFocusIndex(0);
                lAdapter.setFocusIndex(0);
                rAdapter.setFocusIndex(0);
                adapter.setFocusIndex(0);
                right.setFocusIndex(0);
                center.setFocusIndex(0);
                wayRightAdapter.setFocusIndex(0);
                priceAdapter.setFocusIndex(0);
                requestVO = new RentCommitVO();
                params = requestVO.toMap();
                initRequest();
                httpThingsModel.requestThings();
            }
        });

        houseList.setMode(PullToRefreshBase.Mode.BOTH);
        houseList.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(
                    PullToRefreshBase<ListView> refreshView) {


                Log.e("請求參數","下啦");
                requestVO.resetPage();
                params=requestVO.toMap();
                initRequest();
                httpThingsModel.requestThings();
            }

            @Override
            public void onPullUpToRefresh(
                    PullToRefreshBase<ListView> refreshView) {


                requestVO.nextPage();
                params=requestVO.toMap();
               // Log.e("請求參數","上啦"+requestVO.getPage()+params.get("page"));
                initRequest();
                httpThingsModel.requestThings();
            }
        });


    }

    /**
     * 读取城市地区
     * @param inputStream
     * @return
     */
    public static List<ZoneVO> getString(String pid,InputStream inputStream) {
        InputStreamReader inputStreamReader = null;
        try {
            inputStreamReader = new InputStreamReader(inputStream, "gbk");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }
        BufferedReader reader = new BufferedReader(inputStreamReader);

        List<ZoneVO> zoneList = new ArrayList<ZoneVO>();
        String line;
        try {
            while ((line = reader.readLine()) != null) {

                String[] zone = line.split(",");

                if(pid.equals(zone[2])){

                    ZoneVO vo = new ZoneVO();
                    vo.setId(zone[0]);
                    vo.setName(zone[1]);
                    vo.setPid(zone[2]);
                    vo.setLat(zone[3]);
                    vo.setLng(zone[4]);
                    zoneList.add(vo);
                }


            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return zoneList;
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                break;
            case R.id.ll_zone:

                zoneRed.setVisibility(View.VISIBLE);
                priceRed.setVisibility(View.INVISIBLE);
                sellRed.setVisibility(View.INVISIBLE);
                wayRed.setVisibility(View.INVISIBLE);



                txtZone.setTextColor(getResources().getColor(R.color.base_color));
                txtWay.setTextColor(getResources().getColor(R.color.bottom_gray));
                txtPrice.setTextColor(getResources().getColor(R.color.bottom_gray));
                txtSell.setTextColor(getResources().getColor(R.color.bottom_gray));

                imgZone.setImageDrawable(getResources().getDrawable(R.mipmap.triangle_2x));
                imgWay.setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));
                imgPrice.setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));
                imgSell.setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));
                if (pop != null && pop.isShowing()) {
                    pop.dismiss();


                } else {

                    pop.showAsDropDown(llChoose);
                }
                break;
            case R.id.ll_way:

                zoneRed.setVisibility(View.INVISIBLE);
                priceRed.setVisibility(View.INVISIBLE);
                sellRed.setVisibility(View.INVISIBLE);
                wayRed.setVisibility(View.VISIBLE);

                txtZone.setTextColor(getResources().getColor(R.color.bottom_gray));
                txtWay.setTextColor(getResources().getColor(R.color.base_color));
                txtPrice.setTextColor(getResources().getColor(R.color.bottom_gray));
                txtSell.setTextColor(getResources().getColor(R.color.bottom_gray));

                imgZone.setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));
                imgWay.setImageDrawable(getResources().getDrawable(R.mipmap.triangle_2x));
                imgPrice.setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));
                imgSell.setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));

                if (waypop != null && waypop.isShowing()) {
                    waypop.dismiss();
                } else {

                    waypop.showAsDropDown(llChoose);
                }
                break;
            case R.id.ll_sell:

                zoneRed.setVisibility(View.INVISIBLE);
                priceRed.setVisibility(View.INVISIBLE);
                sellRed.setVisibility(View.VISIBLE);
                wayRed.setVisibility(View.INVISIBLE);

                txtZone.setTextColor(getResources().getColor(R.color.bottom_gray));
                txtWay.setTextColor(getResources().getColor(R.color.bottom_gray));
                txtPrice.setTextColor(getResources().getColor(R.color.bottom_gray));
                txtSell.setTextColor(getResources().getColor(R.color.base_color));

                imgZone.setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));
                imgWay.setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));
                imgPrice.setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));
                imgSell.setImageDrawable(getResources().getDrawable(R.mipmap.triangle_2x));
                if (sellpop != null && sellpop.isShowing()) {
                    sellpop.dismiss();
                } else {

                    sellpop.showAsDropDown(llChoose);
                }
                break;

            case R.id.ll_price:

                zoneRed.setVisibility(View.INVISIBLE);
                priceRed.setVisibility(View.VISIBLE);
                sellRed.setVisibility(View.INVISIBLE);
                wayRed.setVisibility(View.INVISIBLE);

                txtZone.setTextColor(getResources().getColor(R.color.bottom_gray));
                txtWay.setTextColor(getResources().getColor(R.color.bottom_gray));
                txtPrice.setTextColor(getResources().getColor(R.color.base_color));
                txtSell.setTextColor(getResources().getColor(R.color.bottom_gray));

                imgZone.setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));
                imgWay.setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));
                imgPrice.setImageDrawable(getResources().getDrawable(R.mipmap.triangle_2x));
                imgSell.setImageDrawable(getResources().getDrawable(R.mipmap.combo_home_chose_nor2x));
                if (pricepop != null && pricepop.isShowing()) {
                    pricepop.dismiss();
                } else {

                    pricepop.showAsDropDown(llChoose);
                }
                break;
            case R.id.ll_search:

                if (searchpop != null && searchpop.isShowing()) {
                    searchpop.dismiss();
                } else {
                    //顯示鍵盤
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

                    searchpop.showAsDropDown(layoutTitle);
                }
                break;
            //排序
            case R.id.floating_button:

                if (sortpop != null && sortpop.isShowing()) {
                    sortpop.dismiss();
                } else {
                    ColorDrawable dw = new ColorDrawable(0x30000000);
                    sortpop.setBackgroundDrawable(dw);
                    sortpop.showAtLocation(getCurrentFocus(), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                }

                break;
            default:
                break;
        }

    }

    private void initZonePopwindow(){
        LayoutInflater myinflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contentView=myinflater.inflate(R.layout.popwindow_zone, null);

//        View contentView = LayoutInflater.from(SellHouseActivity.this).inflate(
//                R.layout.publish_choose_type, null);

        pop = new PopupWindow(contentView,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, true);

        pop.setTouchable(true);
        //  ColorDrawable dw = new ColorDrawable(getResources().getColor(R.color.backgroud_light_I));
        pop.setBackgroundDrawable(new BitmapDrawable());

        ListView leftListView = (ListView)contentView.findViewById(R.id.list_left);
        ListView centerListView = (ListView)contentView.findViewById(R.id.list_center);
        rightListView = (ListView)contentView.findViewById(R.id.list_right);


        leftListItems.add("區域");
        leftListItems.add("捷運");
        leftListItems.add("附近");

        left = new LeftAdapter(SellHouseActivity.this);
        leftListView.setAdapter(left);


        center = new CenterAdapter(SellHouseActivity.this);
        centerListView.setAdapter(center);

        right = new RightAdapter(SellHouseActivity.this);
        rightListView.setAdapter(right);



    }

    private void initWayPopwindow(){
        LayoutInflater inflater1=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view1=inflater1.inflate(R.layout.popwindow_way, null);

        waypop = new PopupWindow(view1,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, true);

        wayList.add("不限");
        wayList.add("住宅");
        wayList.add("店面");
        wayList.add("辦公室");
        wayList.add("廠房");
        wayList.add("車位");
        wayList.add("土地");


        ListView way = (ListView) view1.findViewById(R.id.list);

        waypop.setTouchable(true);
        waypop.setBackgroundDrawable(new BitmapDrawable());

        //Toast.makeText(SellHouseActivity.this, strList.size(), Toast.LENGTH_SHORT).show();
        // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.simple_popwindow_list_item,strList);
         adapter = new WayAdapter(SellHouseActivity.this);
        way.setAdapter(adapter);

         rightWay = (ListView) view1.findViewById(R.id.list_right);
         wayRightAdapter = new WayRightAdapter(SellHouseActivity.this);
        rightWay.setAdapter(wayRightAdapter);


    }

    private void initPricePopWindow(){

        LayoutInflater inflater2=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view2=inflater2.inflate(R.layout.popwindow_price, null);

        ListView pListView = (ListView)view2.findViewById(R.id.price_list);

        maxPrice= (TextView)view2.findViewById(R.id.max_price);
        minPrice= (TextView)view2.findViewById(R.id.min_price);
        maxPrice.setText("萬");
        minPrice.setText("萬");


        LinearLayout llBottom = (LinearLayout)view2.findViewById(R.id.ll_bottom);
        priceList.add("不限");
        priceList.add("500萬以下");
        priceList.add("500 ~ 1,000萬");
        priceList.add("1,000 ~ 1,500萬");
        priceList.add("1,500 ~ 2,000萬");
        priceList.add("2,000 ~ 4,000萬");
        priceList.add("4,000萬以上");

         priceAdapter = new PriceAdapter(SellHouseActivity.this);
        pListView.setAdapter(priceAdapter);

        pricepop = new PopupWindow(view2,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, true);

        pricepop.setTouchable(true);
        pricepop.setBackgroundDrawable(new BitmapDrawable());

        llBottom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pricepop.dismiss();
                if (pricesendpop != null && pricesendpop.isShowing()) {
                    pricesendpop.dismiss();
                } else {

                    pricesendpop.showAtLocation(getCurrentFocus(), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);

                }

            }
        });


    }

    private void initPriceSendPopWindow(){

        LayoutInflater inflater2=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view2=inflater2.inflate(R.layout.popwindow_price_send, null);


        pricesendpop = new PopupWindow(view2,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, true);

        pricesendpop.setTouchable(true);
        pricesendpop.setBackgroundDrawable(new BitmapDrawable());



        TextView txtPriceOk = (TextView)view2.findViewById(R.id.txt_price_ok);
        final EditText et_price_min= (EditText)view2.findViewById(R.id.et_price_min);
       final EditText et_price_max= (EditText)view2.findViewById(R.id.et_price_max);
        et_price_min.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                      InputMethodManager imm=(InputMethodManager)et_price_min.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

                      imm.toggleSoftInput(0,InputMethodManager.SHOW_FORCED);
                }
            }
        });
        txtPriceOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                pricesendpop.dismiss();
                if(!StringUtil.isBlank(String.valueOf(et_price_min.getText()))){
                    requestVO.setSelfprice1(Integer.parseInt(String.valueOf(et_price_min.getText())));
                }
                if(!StringUtil.isBlank(String.valueOf(et_price_max.getText()))){
                    requestVO.setSelfprice2(Integer.parseInt(String.valueOf(et_price_max.getText())));
                }

                params=requestVO.toMap();
                initRequest();
                httpThingsModel.requestThings();
            }
        });



    }

    private void initSellPopwindow(){

        LayoutInflater inflater3=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view3=inflater3.inflate(R.layout.popwindow_sell, null);

        sellpop = new PopupWindow(view3,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, true);

        sellpop.setTouchable(true);
        sellpop.setBackgroundDrawable(new BitmapDrawable());

        sellList.add("类型");
        sellList.add("格局");
        sellList.add("坪數");

        sellRightList.clear();
        sellRightList.add("不限");
        sellRightList.add("公寓");
        sellRightList.add("電梯大樓");
        sellRightList.add("電梯大樓（飯店式管理）");
        sellRightList.add("豪宅");
        sellRightList.add("別墅");
        sellRightList.add("套房");
        sellRightList.add("四合院");
        sellRightList.add("平房");
        sellRightList.add("透天厝");
        sellRightList.add("樓中樓");
        sellRightList.add("其他");

        ListView lListView = (ListView)view3.findViewById(R.id.left_list);
        ListView rListView = (ListView)view3.findViewById(R.id.right_list);

         lAdapter = new SellLeftAdapter(SellHouseActivity.this);
        lListView.setAdapter(lAdapter);

        rAdapter = new SellRightAdapter(SellHouseActivity.this);
        rListView.setAdapter(rAdapter);



    }


    private void initSearchPopwindow(){

        LayoutInflater inflater3=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view3=inflater3.inflate(R.layout.popwindow_search, null);

        searchpop = new PopupWindow(view3,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, true);

        searchpop.setTouchable(true);
        searchpop.setBackgroundDrawable(new BitmapDrawable());


        final EditText etSearch = (EditText)view3.findViewById(R.id.et_search);

        InputMethodManager inputManager = (InputMethodManager)etSearch.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.showSoftInput(etSearch, 0);
        etSearch.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if(keyCode==KeyEvent.KEYCODE_ENTER){
                    searchpop.dismiss();
                   // if(!StringUtil.isBlank(String.valueOf(etSearch.getText()))){
                        requestVO.setSearchKey(String.valueOf(etSearch.getText()));
                  //  }
//                    //顯示鍵盤
//                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//                    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

                    params = requestVO.toMap();
                    initRequest();
                    httpThingsModel.requestThings();
                    txtSearchContent.setVisibility(View.GONE);
                    etSearchContent.setVisibility(View.VISIBLE);
                    etSearchContent.setText(String.valueOf(etSearch.getText()));
                }
                return false;
            }
        });





    }

    private void initSortPopwindow(){

        LayoutInflater inflater3=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view3=inflater3.inflate(R.layout.popwindow_sort, null);

        sortpop = new PopupWindow(view3,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, true);

        sortpop.setTouchable(true);
        sortpop.setBackgroundDrawable(new BitmapDrawable());

        sortList.add("默認排序");
        sortList.add("發佈時間從新至舊");
        sortList.add("物件坪數從小至大");
        sortList.add("物件坪數從大至小");
        sortList.add("物件價格從高至低");
        sortList.add("物件價格從低至高");

        ListView sortlist = (ListView)view3.findViewById(R.id.list_sort);
        SortAdapter sortAdapter = new SortAdapter(SellHouseActivity.this);
        sortlist.setAdapter(sortAdapter);

    }



    public class LeftAdapter extends BaseAdapter {


        private  TextView oldChooseTextView   = null;
        private ImageView oldChooseImageView = null;
        private Map<String,TextView> map = new HashMap<String,TextView>();
        private LayoutInflater mInflater;

        private int focusPosition=0;
        public LeftAdapter(Context context){
            this.mInflater = LayoutInflater.from(context);
            oldChooseTextView = new TextView(SellHouseActivity.this);
        }

        @Override
        public int getCount() {
            return leftListItems.size();
        }

        @Override
        public Object getItem(int position) {
            return leftListItems.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View myconvertView, ViewGroup parent) {

            View leftconvertView = mInflater.inflate(R.layout.popwindow_zone_center_item, null);
            final String obj = leftListItems.get(position);
            final TextView txtName = (TextView) leftconvertView
                    .findViewById(R.id.txt_content);
            txtName.setText(obj);

            if(position==focusPosition){
                ImageView imgListGoRight =(ImageView)leftconvertView.findViewById(R.id.img_choose);

                imgListGoRight.setVisibility(View.VISIBLE);
                // map.put("0",txtName);
                // txtName.setTag(0);
                oldChooseTextView=(TextView) leftconvertView.findViewById(R.id.txt_content);
                oldChooseTextView.setTextColor(getResources().getColor(R.color.base_color));
                oldChooseImageView = imgListGoRight;
            }

            leftconvertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

//                    oldChooseTextView.setTextColor(getResources().getColor(R.color.bottom_gray));
//                    oldChooseImageView.setVisibility(View.INVISIBLE);
//
//                    ImageView imgListGoRight =(ImageView)v.findViewById(R.id.img_choose);
//                    oldChooseImageView =imgListGoRight;
//                    final TextView txtName = (TextView) v
//                            .findViewById(R.id.txt_content);
//                    txtName.setTextColor(getResources().getColor(R.color.base_color));
//                    txtName.setTag(0,txtName);
//                    oldChooseTextView=txtName;
//                    if(imgListGoRight.getVisibility()==View.INVISIBLE){
//                        imgListGoRight.setVisibility(View.VISIBLE);
//                    }

                    rightListView.setVisibility(View.GONE);

                    setFocusIndex(position);
                    notifyDataSetChanged();;
                    fillZone(position);


                }
            });

            return leftconvertView;
        }

        public void setFocusIndex(int position){
            this.focusPosition = position;
        }

    }
    //区域
    private void fillZone(int position){

        centerListItems.clear();


        if(position==0){
            ZoneVO zoneVo = new ZoneVO();
            zoneVo.setId("");
            zoneVo.setName("不限");
            centerListItems.add(zoneVo);
            centerListItems.addAll(cityVOs);
//            centerListItems.add("不限");
//            centerListItems.add("台北市");
//            centerListItems.add("新北市");
//            centerListItems.add("台中市");
//            centerListItems.add("台南市");
//            centerListItems.add("高雄市");
        }
        else if(position==1){
//            centerListItems.add("不限");
//            centerListItems.add("淡水信義線");
//            centerListItems.add("文湖線");
//            centerListItems.add("板南線");
            ZoneVO zoneVo = new ZoneVO();
            zoneVo.setId("");
            zoneVo.setName("不限");
            centerListItems.add(zoneVo);
            centerListItems.addAll(linesVOs);

        }
        else if(position==2){
            rightListView.setVisibility(View.GONE);
            List<ZoneVO> vo =  new ArrayList<ZoneVO>();
            ZoneVO zone = new ZoneVO();
            zone.setName("不限");
            vo.add(zone);

            ZoneVO zone1 = new ZoneVO();
            zone1.setName("1 km 內");
            vo.add(zone1);

//            ZoneVO zone2 = new ZoneVO();
//            zone2.setName("1 km");
//            vo.add(zone2);

            ZoneVO zone3 = new ZoneVO();
            zone3.setName("1.5 km");
            vo.add(zone3);

            ZoneVO zone4 = new ZoneVO();
            zone4.setName("2 km");
            vo.add(zone4);

            ZoneVO zone5 = new ZoneVO();
            zone5.setName("2 km以上");
            vo.add(zone5);
//            centerListItems.add("不限");
//            centerListItems.add("1 km 內");
//            centerListItems.add("1 km");
//            centerListItems.add("1.5 km");
//            centerListItems.add("2 km");
//            centerListItems.add("2 km以上");
            centerListItems.addAll(vo);
        }


        center.notifyDataSetChanged();

    }


    public class CenterAdapter extends BaseAdapter {

        private TextView oldChooseTextView   = null;
        private ImageView oldChooseImageView = null;

        private int focusPosition=0;
        private LayoutInflater mInflater;

        public CenterAdapter(Context context){
            this.mInflater = LayoutInflater.from(context);
            oldChooseTextView = new TextView(SellHouseActivity.this);
        }

        @Override
        public int getCount() {
            return centerListItems.size();
        }

        @Override
        public Object getItem(int position) {
            return centerListItems.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View myconvertView, ViewGroup parent) {

            View centerconvertView = mInflater.inflate(R.layout.popwindow_zone_center_item, null);
            final ZoneVO obj = centerListItems.get(position);
            final TextView txtName = (TextView) centerconvertView
                    .findViewById(R.id.txt_content);
            txtName.setText(obj.getName());

            if(position==focusPosition){
                ImageView imgListGoRight =(ImageView)centerconvertView.findViewById(R.id.img_choose);

                if(left.focusPosition!=2){
                    imgListGoRight.setVisibility(View.VISIBLE);
                }

                txtName.setTextColor(getResources().getColor(R.color.base_color));
                oldChooseTextView=(TextView) centerconvertView.findViewById(R.id.txt_content);
                oldChooseImageView = imgListGoRight;
            }

            centerconvertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

//                    oldChooseTextView.setTextColor(getResources().getColor(R.color.bottom_gray));
//                    oldChooseImageView.setVisibility(View.INVISIBLE);
//
//                    ImageView imgListGoRight =(ImageView)v.findViewById(R.id.img_choose);
//                    oldChooseImageView =imgListGoRight;
//                    final TextView txtName = (TextView) v
//                            .findViewById(R.id.txt_content);
//                    txtName.setTextColor(getResources().getColor(R.color.base_color));
//
//                    oldChooseTextView=txtName;
//                    if(imgListGoRight.getVisibility()==View.INVISIBLE){
//                        imgListGoRight.setVisibility(View.VISIBLE);
//                    }

                    setFocusIndex(position);

                    if(!StringUtil.isBlank(obj.getId())){
                        //区域
                        if(left.focusPosition==0){
                            requestVO.setArea(Integer.parseInt(obj.getId()));
                        }
                        //捷运
                        else if(left.focusPosition==1){

                        }
                        //附近
                        else if(left.focusPosition==2){
                            pop.dismiss();
                            if(focusPosition==0){
                                requestVO.setScope(1);
                            }
                          else  if(focusPosition==1){
                                requestVO.setScope(Float.parseFloat(String.valueOf(1.5)));
                            }
                            //
                            else  if(focusPosition==2){
                                requestVO.setScope(2);
                            }
                            //2km以上
                            else  if(focusPosition==3){
                                requestVO.setScope(100);
                            }
                            requestVO.setLat(Float.parseFloat(obj.getLat()));
                            requestVO.setLng(Float.parseFloat(obj.getLng()));
                        }

                        params=requestVO.toMap();
                        initRequest();
                        httpThingsModel.requestThings();
                    }
                    else{
                        pop.dismiss();
                    }
                    notifyDataSetChanged();

                    fillArea(obj.getId());


                }
            });

            return centerconvertView;
        }
        public void setFocusIndex(int position){
            this.focusPosition = position;
        }

    }

    private void fillArea(String id){



        rigthListItems.clear();
        if(left.focusPosition==0){
            rightListView.setVisibility(View.VISIBLE);

            ZoneVO zoneVo = new ZoneVO();
            zoneVo.setId("");
            zoneVo.setName("不限");
            rigthListItems.add(zoneVo);
            InputStream areainputStream = getResources().openRawResource(R.raw.area);

            rigthListItems.addAll(getString(id,areainputStream));

            right.notifyDataSetChanged();
        }
        else if(left.focusPosition==1){

            rightListView.setVisibility(View.VISIBLE);
            ZoneVO zoneVo = new ZoneVO();
            zoneVo.setId("");
            zoneVo.setName("不限");
            rigthListItems.add(zoneVo);
            InputStream areainputStream = getResources().openRawResource(R.raw.station);

            rigthListItems.addAll(getString(id,areainputStream));
            right.notifyDataSetChanged();
        }
        else{
            rightListView.setVisibility(View.GONE);
        }


    }


    public class RightAdapter extends BaseAdapter {



        private LayoutInflater mInflater;
        private int focusPosition=0;

        public RightAdapter(Context context){
            this.mInflater = LayoutInflater.from(context);
        }

        @Override
        public int getCount() {
            return rigthListItems.size();
        }

        @Override
        public Object getItem(int position) {
            return rigthListItems.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            convertView = mInflater.inflate(R.layout.popwindow_zone_item, null);


            final ZoneVO obj = rigthListItems.get(position);
            final TextView txtName = (TextView) convertView
                    .findViewById(R.id.txt_content);
            txtName.setText(obj.getName());


            if(position==focusPosition){

                txtName.setTextColor(getResources().getColor(R.color.base_color));

            }
            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    setFocusIndex(position);
                    pop.dismiss();
                    if(!StringUtil.isBlank(obj.getId())){
                        if(left.focusPosition==0){
                            requestVO.setArea(Integer.parseInt(obj.getId()));
                        }
                        else if(left.focusPosition==1){

                            requestVO.setLat(Float.parseFloat(obj.getLat()));
                            requestVO.setLng(Float.parseFloat(obj.getLng()));
                        }

                        params=requestVO.toMap();
                        initRequest();
                        httpThingsModel.requestThings();
                    }


                    notifyDataSetChanged();
                }
            });


            return convertView;
        }

        public void setFocusIndex(int position){
            this.focusPosition = position;
        }

    }

    public class WayAdapter extends BaseAdapter {

        private LayoutInflater mInflater;

        private int focusPosition=0;
        public WayAdapter(Context context) {

        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return wayList.size();
        }

        @Override
        public Object getItem(int arg0) {
            // TODO Auto-generated method stub
            return wayList.get(arg0);
        }

        @Override
        public long getItemId(int arg0) {
            // TODO Auto-generated method stub
            return arg0;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            convertView = inflater.inflate(R.layout.simple_popwindow_list_item, null);

            final String obj = wayList.get(position);
            final TextView txtName = (TextView) convertView
                    .findViewById(R.id.txt_way_content);
            txtName.setText(obj);

            if(position==focusPosition){

                txtName.setTextColor(getResources().getColor(R.color.base_color));

            }
            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setFocusIndex(position);

                    if(focusPosition==0){
                        waypop.dismiss();
                        requestVO.setHouse(0);
                        requestVO.setStore(0);
                        requestVO.setOffice(0);
                        requestVO.setWorkshop(0);
                        requestVO.setStall(0);
                        requestVO.setLand(0);
                        txtWay.setText("不限");
                    }
                    //住宅
                   else  if(focusPosition==1){
                        requestVO.setHouse(1);
                         requestVO.setStore(0);
                         requestVO.setOffice(0);
                         requestVO.setWorkshop(0);
                         requestVO.setStall(0);
                         requestVO.setLand(0);
                         txtWay.setText("住宅");
                    }

                    //店面
                    else if(focusPosition==2){
                         requestVO.setHouse(0);
                         requestVO.setStore(1);
                         requestVO.setOffice(0);
                         requestVO.setWorkshop(0);
                         requestVO.setStall(0);
                         requestVO.setLand(0);
                         txtWay.setText("店面");
                    }
                    //办公室
                    else if(focusPosition==3){
                         requestVO.setHouse(0);
                         requestVO.setStore(0);
                         requestVO.setOffice(1);
                         requestVO.setWorkshop(0);
                         requestVO.setStall(0);
                         requestVO.setLand(0);
                         txtWay.setText("办公室");
                    }
                    //厂房
                    else if(focusPosition==4){
                         requestVO.setHouse(0);
                         requestVO.setStore(0);
                         requestVO.setOffice(0);
                         requestVO.setWorkshop(0);
                         requestVO.setStall(0);
                         requestVO.setLand(0);
                         txtWay.setText("厂房");
                    }
                     //車位
                     else if(focusPosition==5){
                         requestVO.setHouse(0);
                         requestVO.setStore(0);
                         requestVO.setOffice(0);
                         requestVO.setWorkshop(0);
                         requestVO.setStall(1);
                         requestVO.setLand(0);
                         txtWay.setText("車位");
                     }
                     //土地
                     else if(focusPosition==6){
                         requestVO.setHouse(0);
                         requestVO.setStore(0);
                         requestVO.setOffice(0);
                         requestVO.setWorkshop(0);
                         requestVO.setStall(0);
                         requestVO.setLand(1);
                         txtWay.setText("土地");
                     }
                        if(focusPosition!=0){
                             rightWay.setVisibility(View.VISIBLE);
                            fillWayRight(position);
                        }
                    else{
                            rightWay.setVisibility(View.GONE);
                     }
                        params=requestVO.toMap();
                        initRequest();
                        httpThingsModel.requestThings();



                    notifyDataSetChanged();

                }
            });

            return convertView;
        }

        public void setFocusIndex(int position){
            this.focusPosition = position;
        }
    }

    private void fillWayRight(int position){
        wayRightList.clear();
        //住宅
        if(position==1){

            wayRightList.add("不限");
            wayRightList.add("公寓");
            wayRightList.add("電梯大樓");
            wayRightList.add("電梯大樓（飯店式管理）");
            wayRightList.add("豪宅");
            wayRightList.add("別墅");
            wayRightList.add("套房");
            wayRightList.add("四合院");
            wayRightList.add("平房");
            wayRightList.add("透天厝");
            wayRightList.add("樓中樓");
            wayRightList.add("其他");

        }
        else if(position==2){
            wayRightList.add("不限");
            wayRightList.add("住店");
            wayRightList.add("賣場店面");
            wayRightList.add("三角窗店面");
            wayRightList.add("透天店面");
            wayRightList.add("市場攤位");
            wayRightList.add("辦公大樓配套店面");
            wayRightList.add("飯店配套店面");
            wayRightList.add("社區店面");
            wayRightList.add("觀光店面");
            wayRightList.add("商業街店面");
            wayRightList.add("其他");
        }
        else if(position==3){
            wayRightList.add("不限");
            wayRightList.add("純辦公大樓");
            wayRightList.add("住辦兩用");
            wayRightList.add("店住辦");
            wayRightList.add("工業住辦");
            wayRightList.add("其他");
        }

        else if(position==4){
            wayRightList.add("不限");
            wayRightList.add("純厰房");
            wayRightList.add("厰房厰辦");
            wayRightList.add("倉庫");
            wayRightList.add("其他");
        }

        else if(position==5){
            wayRightList.add("不限");
            wayRightList.add("平面");
            wayRightList.add("機械");

        }
        else if(position==6){
            wayRightList.add("不限");
            wayRightList.add("住宅用地");
            wayRightList.add("商業用地");
            wayRightList.add("工業用地");
            wayRightList.add("農地");
            wayRightList.add("農牧地");
            wayRightList.add("山林牧地");
            wayRightList.add("墓地");
            wayRightList.add("休閑用地");
            wayRightList.add("停車場用地");
            wayRightList.add("道路用地");
            wayRightList.add("畸零地");
            wayRightList.add("礦鹽地");
            wayRightList.add("養殖地");
            wayRightList.add("其他");

        }

         wayRightAdapter.notifyDataSetChanged();

    }

    public class WayRightAdapter extends BaseAdapter {

        private LayoutInflater mInflater;

        private int focusPosition=0;
        public WayRightAdapter(Context context) {

        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return wayRightList.size();
        }

        @Override
        public Object getItem(int arg0) {
            // TODO Auto-generated method stub
            return wayRightList.get(arg0);
        }

        @Override
        public long getItemId(int arg0) {
            // TODO Auto-generated method stub
            return arg0;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            convertView = inflater.inflate(R.layout.simple_popwindow_list_item, null);

            final String obj = wayRightList.get(position);
            final TextView txtName = (TextView) convertView
                    .findViewById(R.id.txt_way_content);
            txtName.setText(obj);

            if(position==focusPosition){

                txtName.setTextColor(getResources().getColor(R.color.base_color));

            }
            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setFocusIndex(position);
                    waypop.dismiss();
                    //
                    if(adapter.focusPosition==0){


                        txtWay.setText("不限");
                    }
                    //住宅
                    else  if(adapter.focusPosition==1){
                        if(position==0){
                            // requestVO.setModal(4);
                        }
                        else if(position==1){
                            requestVO.setModal(4);
                        }
                        //电梯大楼
                        else if(position==2){
                            requestVO.setModal(2);
                        }
                        else if(position==3){
                            requestVO.setModal(16);
                        }
                        //豪宅
                        else if(position==4){
                            requestVO.setModal(1);
                        }
                        else if(position==5){
                            requestVO.setModal(6);
                        }
                        else if(position==6){
                            requestVO.setModal(11);
                        }
                        else if(position==7){
                            requestVO.setModal(18);
                        }
                        else if(position==8){
                            requestVO.setModal(13);
                        }
                        else if(position==9){
                            requestVO.setModal(5);
                        }
                        else if(position==10){
                            requestVO.setModal(14);
                        }
                        else if(position==11){
                            requestVO.setModal(15);
                        }
                        txtWay.setText("住宅");
                    }

                    //店面
                    else if(adapter.focusPosition==2){
                        if(position==0){
                            // requestVO.setModal(4);
                        }
                        //住店
                        else if(position==1){
                            requestVO.setModal(1);
                        }
                        //賣場店面
                        else if(position==2){
                            requestVO.setModal(2);
                        }
                        //三角窗店面
                        else if(position==3){
                            requestVO.setModal(3);
                        }
                        //
                        else if(position==4){
                            requestVO.setModal(4);
                        }
                        else if(position==5){
                            requestVO.setModal(6);
                        }
                        else if(position==6){
                            requestVO.setModal(10);
                        }
                        else if(position==7){
                            requestVO.setModal(11);
                        }
                        else if(position==8){
                            requestVO.setModal(12);
                        }
                        else if(position==9){
                            requestVO.setModal(13);
                        }
                        else if(position==10){
                            requestVO.setModal(14);
                        }
                        else if(position==11){
                            requestVO.setModal(7);
                        }
                        txtWay.setText("店面");
                    }
                    //办公室
                    else if(adapter.focusPosition==3){
                        if(position==0){
                            // requestVO.setModal(4);
                        }
                        else if(position==1){
                            requestVO.setModal(1);
                        }
                        else if(position==2){
                            requestVO.setModal(2);
                        }
                        else if(position==3){
                            requestVO.setModal(3);
                        }
                        else if(position==4){
                            requestVO.setModal(4);
                        }
                        else if(position==5){
                            requestVO.setModal(5);
                        }
                        txtWay.setText("办公室");
                    }
                    //厂房
                    else if(adapter.focusPosition==4){
                        if(position==0){
                            // requestVO.setModal(4);
                        }
                        else if(position==1){
                            requestVO.setModal(1);
                        }
                        else if(position==2){
                            requestVO.setModal(2);
                        }
                        else if(position==3){
                            requestVO.setModal(3);
                        }
                        else if(position==4){
                            requestVO.setModal(4);
                        }

                        txtWay.setText("厂房");
                    }
                    //車位
                    else if(adapter.focusPosition==5){
                        if(position==0){
                            // requestVO.setModal(4);
                        }
                        else if(position==1){
                            requestVO.setModal(1);
                        }
                        else if(position==2){
                            requestVO.setModal(2);
                        }
                        else if(position==3){
                            requestVO.setModal(3);
                        }
                        else if(position==4){
                            requestVO.setModal(4);
                        }
                        else if(position==5){
                            requestVO.setModal(5);
                        }
                        txtWay.setText("車位");
                    }
                    //土地
                    else if(adapter.focusPosition==6){


                        if(position==0){
                            // requestVO.setModal(4);
                        }
                        else if(position==1){
                            requestVO.setModal(1);
                        }
                        else if(position==2){
                            requestVO.setModal(2);
                        }
                        else if(position==3){
                            requestVO.setModal(3);
                        }
                        else if(position==4){
                            requestVO.setModal(4);
                        }
                        else if(position==5){
                            requestVO.setModal(5);
                        }

                        else if(position==6){
                            requestVO.setModal(6);
                        }
                        else if(position==7){
                            requestVO.setModal(7);
                        }
                        else if(position==8){
                            requestVO.setModal(8);
                        }
                        else if(position==9){
                            requestVO.setModal(9);
                        }
                        else if(position==10){
                            requestVO.setModal(10);
                        }
                        else if(position==11){
                            requestVO.setModal(11);
                        }
                        else if(position==12){
                            requestVO.setModal(12);
                        }
                        else if(position==13){
                            requestVO.setModal(13);
                        }
                        else if(position==14){
                            requestVO.setModal(14);
                        }

                        txtWay.setText("土地");
                    }


                    params=requestVO.toMap();
                    initRequest();
                    httpThingsModel.requestThings();



                    notifyDataSetChanged();

                }
            });

            return convertView;
        }

        public void setFocusIndex(int position){
            this.focusPosition = position;
        }
    }



    public class PriceAdapter extends BaseAdapter {

        private LayoutInflater mInflater;

        private int focusPosition=0;
        public PriceAdapter(Context context) {

        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return priceList.size();
        }

        @Override
        public Object getItem(int arg0) {
            // TODO Auto-generated method stub
            return priceList.get(arg0);
        }

        @Override
        public long getItemId(int arg0) {
            // TODO Auto-generated method stub
            return arg0;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            convertView = inflater.inflate(R.layout.simple_popwindow_list_item, null);
            final String obj = priceList.get(position);
            final TextView txtName = (TextView) convertView
                    .findViewById(R.id.txt_way_content);
            txtName.setText(obj);

            if(position==focusPosition){


                txtName.setTextColor(getResources().getColor(R.color.base_color));

            }
            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setFocusIndex(position);
                    pricepop.dismiss();
                    if(focusPosition==0){
                        requestVO.setSelfprice1(0);
                        requestVO.setSelfprice2(0);
                        txtPrice.setText("不限");
                    }
                   else if(focusPosition==1){
                        requestVO.setSelfprice1(0);
                        requestVO.setSelfprice2(500);
                        txtPrice.setText("500萬");
                    }
                    else if(focusPosition==2){
                        requestVO.setSelfprice1(5000);
                        requestVO.setSelfprice2(10000);
                        txtPrice.setText("500-1,000萬");
                    }
                    else if(focusPosition==3){
                        requestVO.setSelfprice1(1000);
                        requestVO.setSelfprice2(1500);
                        txtPrice.setText("1500萬");
                    }
                    else if(focusPosition==4){
                        requestVO.setSelfprice1(1500);
                        requestVO.setSelfprice2(2000);
                        txtPrice.setText("2000萬");
                    }
                    else if(focusPosition==5){
                        requestVO.setSelfprice1(2000);
                        requestVO.setSelfprice2(4000);
                        txtPrice.setText("4000萬");
                    }
                    else if(focusPosition==6){
                        requestVO.setSelfprice1(4000);
                        requestVO.setSelfprice2(0);
                        txtPrice.setText("4000萬");
                    }


                        params=requestVO.toMap();
                        initRequest();
                        httpThingsModel.requestThings();


                    notifyDataSetChanged();

                }
            });
            return convertView;
        }

        public void setFocusIndex(int position){
            this.focusPosition = position;
        }
    }


    public class SellLeftAdapter extends BaseAdapter {


        private int focusPosition = 0;
        public SellLeftAdapter(Context context){

        }

        @Override
        public int getCount() {
            return sellList.size();
        }

        @Override
        public Object getItem(int position) {
            return sellList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            convertView = inflater.inflate(R.layout.popwindow_zone_item, null);
            final String obj = sellList.get(position);
            final TextView txtName = (TextView) convertView
                    .findViewById(R.id.txt_content);
            if(position==focusPosition){
                ImageView imgListGoRight =(ImageView)convertView.findViewById(R.id.img_choose);

                imgListGoRight.setVisibility(View.VISIBLE);


                txtName.setTextColor(getResources().getColor(R.color.base_color));

            }
            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setFocusIndex(position);
                    notifyDataSetChanged();

                    fillSell(position);
                }
            });
            txtName.setText(obj);
            return convertView;
        }

        public void setFocusIndex(int position){
            this.focusPosition = position;
        }

    }

    private void fillSell(int position){
        //格局
        if(position==1){
            sellRightList.clear();
            sellRightList.add("不限");
            sellRightList.add("1房");
            sellRightList.add("2房");
            sellRightList.add("3房");
            sellRightList.add("4房");
            sellRightList.add("5房以上");

            rAdapter.notifyDataSetChanged();
        }
        else if(position==2){
            sellRightList.clear();
            sellRightList.add("不限");
            sellRightList.add("10坪以下");
            sellRightList.add("10 - 20坪");
            sellRightList.add("20 - 30坪");
            sellRightList.add("30 - 40坪");
            sellRightList.add("40 - 50坪");
            sellRightList.add("50坪以上");

            rAdapter.notifyDataSetChanged();


        }
        //类型
        else if(position==0){

            sellRightList.clear();
            sellRightList.add("不限");
            sellRightList.add("公寓");
            sellRightList.add("電梯大樓");
            sellRightList.add("電梯大樓（飯店式管理）");
            sellRightList.add("豪宅");
            sellRightList.add("別墅");
            sellRightList.add("套房");
            sellRightList.add("四合院");
            sellRightList.add("平房");
            sellRightList.add("透天厝");
            sellRightList.add("樓中樓");
            sellRightList.add("其他");


            rAdapter.notifyDataSetChanged();

        }




    }

    public class SellRightAdapter extends BaseAdapter {


        private LayoutInflater mInflater;
        private int focusPosition=0;

        public SellRightAdapter(Context context){
            this.mInflater = LayoutInflater.from(context);
        }

        @Override
        public int getCount() {
            return sellRightList.size();
        }

        @Override
        public Object getItem(int position) {
            return sellRightList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            convertView = mInflater.inflate(R.layout.popwindow_zone_item, null);
            final String obj = sellRightList.get(position);
            final TextView txtName = (TextView) convertView
                    .findViewById(R.id.txt_content);
            txtName.setText(obj);
            if(position==focusPosition){

                txtName.setTextColor(getResources().getColor(R.color.base_color));

            }

            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setFocusIndex(position);
                    Log.e("lAdapter.focusPosition",""+lAdapter.focusPosition);
                    sellpop.dismiss();
                    //类型
                    if (lAdapter.focusPosition == 0) {
                        if(position==0){
                            // requestVO.setModal(4);
                        }
                        else if(position==1){
                            requestVO.setModal(4);
                        }
                        //电梯大楼
                        else if(position==2){
                            requestVO.setModal(2);
                        }
                        else if(position==3){
                            requestVO.setModal(16);
                        }
                        //豪宅
                        else if(position==4){
                            requestVO.setModal(1);
                        }
                        else if(position==5){
                            requestVO.setModal(6);
                        }
                        else if(position==6){
                            requestVO.setModal(11);
                        }
                        else if(position==7){
                            requestVO.setModal(18);
                        }
                        else if(position==8){
                            requestVO.setModal(13);
                        }
                        else if(position==9){
                            requestVO.setModal(5);
                        }
                        else if(position==10){
                            requestVO.setModal(14);
                        }
                        else if(position==11){
                            requestVO.setModal(15);
                        }
                    }
                    //格局
                    else if (lAdapter.focusPosition == 1) {
                        //1房
                        if (focusPosition == 0) {
                            requestVO.setRooms(1);
                        }
                        //
                        else if (focusPosition == 1) {

                            requestVO.setRooms(2);
                        }
                        else if (focusPosition == 2) {

                            requestVO.setRooms(3);
                        }
                        else if (focusPosition == 3) {

                            requestVO.setRooms(4);
                        }
                        else if (focusPosition == 5) {

                            requestVO.setRooms(5);
                        }
                    }
                    //坪数
                    else if (lAdapter.focusPosition == 2) {
                        //10
                        if(focusPosition == 0){
                            requestVO.setSelfsquare1(0);
                            requestVO.setSelfsquare2(0);
                        }
                        else if (focusPosition == 1) {
                            requestVO.setSelfsquare2(10);
                            requestVO.setSelfsquare1(0);
                        }
                        //
                        else if (focusPosition == 2) {
                            requestVO.setSelfsquare1(10);
                            requestVO.setSelfsquare2(20);
                        }
                        else if (focusPosition == 3) {
                            requestVO.setSelfsquare1(20);
                            requestVO.setSelfsquare2(30);
                        }
                        else if (focusPosition == 4) {
                            requestVO.setSelfsquare1(30);
                            requestVO.setSelfsquare2(40);
                        }
                        else if (focusPosition == 5) {
                            requestVO.setSelfsquare1(40);
                            requestVO.setSelfsquare2(50);
                        }
                        else if (focusPosition == 6) {
                            requestVO.setSelfsquare1(50);
                            requestVO.setSelfsquare2(0);

                        }


                    }
                    params = requestVO.toMap();
                    initRequest();
                    httpThingsModel.requestThings();


                    notifyDataSetChanged();
                }
            });
            return convertView;
        }



        public void setFocusIndex(int position){
            this.focusPosition = position;
        }

    }


    public class SortAdapter extends BaseAdapter {


        private LayoutInflater mInflater;
        private int focusPosition=0;

        public SortAdapter(Context context){
            this.mInflater = LayoutInflater.from(context);
        }

        @Override
        public int getCount() {
            return sortList.size();
        }

        @Override
        public Object getItem(int position) {
            return sortList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            convertView = mInflater.inflate(R.layout.popwindow_zone_item, null);
            final String obj = sortList.get(position);
            final TextView txtName = (TextView) convertView
                    .findViewById(R.id.txt_content);
            txtName.setText(obj);
            if(position==focusPosition){

                txtName.setTextColor(getResources().getColor(R.color.base_color));

            }

            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    sortpop.dismiss();
                    setFocusIndex(position);
                    //更新时间从新到旧
                    if(focusPosition==0){
                        requestVO.setOrder("default");
                    }
                    //發佈時間從新至舊
                    else if(focusPosition==1){

                        requestVO.setOrder("property_added desc");
                    }
                    //坪數從小至大
                    else if(focusPosition==2){
                        requestVO.setOrder("property_lawnarea asc");
                    }
                    else if(focusPosition==3){
                        requestVO.setOrder("property_lawnarea desc");
                    }
                    //租金從高至低
                    else if(focusPosition==4){
                        requestVO.setOrder("property_rentprice desc");
                    }
                    else if(focusPosition==5){
                        requestVO.setOrder("property_rentprice asc");
                    }
                    params = requestVO.toMap();
                 //   Log.e("getOrdergrgetOrder==",""+requestVO.getOrder()+""+params.get("order"));
                    initRequest();
                    httpThingsModel.requestThings();

                    notifyDataSetChanged();



                }
            });
            return convertView;
        }



        public void setFocusIndex(int position){
            this.focusPosition = position;
        }

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    public Action getIndexApiAction() {
        Thing object = new Thing.Builder()
                .setName("SellHouse Page") // TODO: Define a title for the content shown.
                // TODO: Make sure this auto-generated URL is correct.
                .setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
                .build();
        return new Action.Builder(Action.TYPE_VIEW)
                .setObject(object)
                .setActionStatus(Action.STATUS_TYPE_COMPLETED)
                .build();
    }

    @Override
    public void onStart() {
        super.onStart();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client.connect();
        AppIndex.AppIndexApi.start(client, getIndexApiAction());
    }

    @Override
    public void onStop() {
        super.onStop();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        AppIndex.AppIndexApi.end(client, getIndexApiAction());
        client.disconnect();
    }

    public class SellHousePageAdapter extends ArrayAdapter<RentVO> {
        private final String TAG = "SellHousePageAdapter";
        private int resourceId;
        private Context context;
        private boolean isAllItemEnable=true;

        public SellHousePageAdapter(Context context, int resourceId) {
            super(context, resourceId);
            this.context = context;
            this.resourceId = resourceId;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            final RentVO vo = getItem(position);
            View view = null;
            final ItemView itemView;
            if(convertView == null){
                itemView = new ItemView();
                view = LayoutInflater.from(getContext()).inflate(resourceId, null);
                itemView.houseImg = (ImageView)view.findViewById(R.id.img_sell_house_item);
                itemView.areaName = (TextView)view.findViewById(R.id.txt_sell_house_item_area);
                itemView.houseName = (TextView)view.findViewById(R.id.txt_sell_house_item_name);
                itemView.housePrice = (TextView)view.findViewById(R.id.txt_sell_house_item_price);
                itemView.houseAddr = (TextView)view.findViewById(R.id.txt_sell_house_item_address);
                view.setTag(itemView);
            } else {
                view = convertView;
                itemView = (ItemView)view.getTag();
            }

            Images.with(context).load(Uri.parse(vo.getImg())).resize(130,90).into(itemView.houseImg);

            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    sellHousePageAdapter.disableAllItemChoser();
                    String param ="?seq="+vo.getSeq();
                    Log.e("param::==",param);
                    initDetailRequest(param);
                    httpThingsDetailModel.requestThings();
                }
            });
            itemView.houseName.setText(vo.getName());
            if(vo.getRentprice()!=0){
                itemView.housePrice.setText(vo.getRentprice()+"元");
            }

            if(vo.getSaleprice()!=0){

                itemView.housePrice.setText(vo.getSaleprice()+"萬");
            }

            if(vo.getUnitprice()!=0){
                itemView.housePrice.setText(vo.getUnitprice()+"萬/每平米");
                itemView.areaName.setVisibility(View.GONE);
            }

            if(vo.getUnitprice1()!=0&&vo.getUnitprice2()!=0){
                itemView.housePrice.setText(vo.getUnitprice1()+"~"+vo.getUnitprice1()+"萬");
            }
            if(vo.getLawnarea()!=null){
                itemView.areaName.setText(vo.getLawnarea()+"坪");
            }
            else if("1".equals(vo.getType())){

                itemView.areaName.setText("预售屋");
            }
            else if("3".equals(vo.getType())){

                itemView.areaName.setText("新成屋");
            }
            else if("4".equals(vo.getType())){

                itemView.areaName.setText("建构中");
            }

            if(!"".equals(vo.getStreetname())){
                itemView.houseAddr.setText(vo.getStreetname());
            }
            if(!"".equals(vo.getAddr())){
                itemView.houseAddr.setText(vo.getAddr());
            }

            return view;
        }

        @Override
        public long getItemId(int position) {
            return super.getItemId(position);
        }

        @Override
        public int getCount() {
            return super.getCount();
        }

        @Override
        public RentVO getItem(int position) {
            return super.getItem(position);
        }

        @Override
        public boolean isEnabled(int position) {
            return isAllItemEnable;
        }

        public void disableAllItemChoser() {
            isAllItemEnable = false;
            notifyDataSetChanged();
        }
        public void enableItemChoser() {
            isAllItemEnable = true;
            notifyDataSetChanged();
        }

        class ItemView {
            ImageView houseImg;
            TextView houseName;
            TextView housePrice;
            TextView areaName;
            TextView houseAddr;
        }

    }
}
